<template>
  <view class="router-view bcl-active pt-20">
    <view class="bcl-white">
      <uni-cell
        title="账号安全"
        url="/user/setting/security/security"
      ></uni-cell>
      <uni-cell
        title="认证管理"
        url="/user/setting/binding/legalizeManage"
      ></uni-cell>
      <!-- <uni-cell title="消息设置" :show-arrow="false" :no-pointer="true">
        <view slot="value">
          <switch
            :checked="isOpenMessage"
            color="#7ED321"
            @change="changMessageState"
          />
        </view>
      </uni-cell> -->
    </view>

    <view class="bcl-white mt-5">
      <uni-cell title="帮助与反馈" url="/index/modify?type=5"></uni-cell>
      <uni-cell title="联系我们" url="/user/setting/contact"></uni-cell>
      <uni-cell title="隐私协议" url="/user/protocol"></uni-cell>
      <uni-cell title="关于志华网" url="/user/setting/about"></uni-cell>
    </view>

    <view class="mt-50 container">
      <button
        class="uni-button uni-button-lg uni-button-full uni-button-disalbed"
        @tap="toLoginOut"
      >
        退出登录
      </button>

      <view class="text-center mt-40 cl-second">
        <view>Copyright 2009 - 2020</view>
        <view>58.zhihua.com 版权所有</view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapActions, mapState } from "vuex";
import { loginOut } from "@/apis/user";
import uniCell from "@/components/cell";

export default {
  components: {
    uniCell,
  },

  data() {
    return {
      isOpenMessage: false,
    };
  },

  methods: {
    // 修改消息推送状态
    changMessageState() {
      this.isOpenMessage = !this.isOpenMessage;
    },

    /**
     * 退出登录
     */
    toLoginOut() {
      uni.showModal({
        title: "温馨提示",
        content: "您确定要退出登录？",
        success: async (res) => {
          if (res.confirm) {
            let { code } = await loginOut();
            if (code === 200) {
              this.$toast("退出成功");
              this.SET_USER_INFO("");

              if (this.tim) {
                this.tim.logout().then((aaa) => {
                  this.SET_TIM("");
                  uni.setStorageSync("timUserSign", "");
                });
              }
              setTimeout(() => {
                uni.reLaunch({
                  url: "/pages/index/index",
                });
              }, 1000);
            }
          }
        },
      });
    },

    ...mapActions(["SET_USER_INFO", "SET_TIM"]),
  },

  computed: {
    ...mapState(["tim"]),
  },
};
</script>
